import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_application_1/components/boxShadow/index.dart';
import 'package:flutter_application_1/components/log/log.dart';
import 'package:flutter_application_1/provider/dpNotifier.dart';
import 'package:flutter_application_1/route/application.dart';

import 'package:flutter_application_1/components/navBar/topNavBar.dart';
import 'package:flutter_application_1/components/navBar/footerBar/index.dart';
import 'package:flutter_application_1/components/navBar/footerBar/animatedBar.dart';
import 'package:provider/provider.dart';

class MainComponent extends StatefulWidget {
  @override
  MainComponentState createState() => MainComponentState();
}

class MainComponentState extends State<MainComponent> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: const Color(0xFF00D6F7),
      child: TopNavBar(
          title: 'SmartLife',
          child: _PageContainer(context),
          onPressRight: () => {Log.d('touch')}),
    );
  }

  Widget _PageContainer(BuildContext context) {
    final size = MediaQuery.of(context).size;

    final dp = Provider.of<DpNotifier>(context);
    Log.i(dp.data);

    return Container(
        color: const Color.fromARGB(1000, 246, 249, 251),
        width: size.width,
        child: BottomBarNavigationPatternExample(barItems: [
          BarItem(
              text: '开关',
              iconData: Icons.home,
              color: Colors.indigo,
              content: SwitchPage(context)),
          BarItem(
            text: '数据',
            iconData: Icons.favorite_border,
            color: Colors.pinkAccent,
          ),
          BarItem(
            text: '定时',
            iconData: Icons.search,
            color: Colors.yellow.shade900,
          ),
          BarItem(
            text: '详情',
            iconData: Icons.person_outline,
            color: Colors.teal,
          ),
        ]));
  }

  Widget SwitchPage(BuildContext context) {
    final dp = Provider.of<DpNotifier>(context);
    return Container(
      child: Center(
        child: InkWell(
          child: Text(
            '点我改变开关状态 ${dp.data['switch']}',
            style: TextStyle(color: Colors.white, fontSize: 20.0),
          ),
          onTap: () =>
              {dp.onChange('switch', dp.data['switch'] == true ? false : true)},
        ),
      ),
    );
  }
}
